package com.wd.tech.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.wd.tech.R;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends AppCompatActivity implements View.OnClickListener {
    //倒计时3秒
    private int recLen=3;
    TextView tv;
    Timer timer=new Timer();
    private Handler handler;
    private Runnable runnable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        //定义全屏参数
        int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //设置当前窗体为全屏显示
        getWindow().setFlags(flag,flag);
        setContentView(R.layout.activity_welcome);
        initView();

        handler=new Handler();
        handler.postDelayed(runnable=new Runnable() {
            @Override
            public void run() {

                Intent intent = new Intent(WelcomeActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        },3000);//延迟3秒发送Handler消息
    }

    private void initView() {
        tv = findViewById(R.id.tv);

    }
    TimerTask task=new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    tv.setText(""+recLen+"S");
                    recLen--;

                    if (recLen<0){
                        timer.cancel();
                        //倒计时到0的时候隐藏字体
                        tv.setVisibility(View.GONE);
                    }
                }
            });
        }
    };
    @Override
    public void onClick(View v) {

//        switch (v.getId()){
//            case R.id.tv:
//                //从闪屏幕跳转到首页面
//                Intent intent = new Intent(WelcomeActivity.this,LoginActivity.class);
//                startActivity(intent);
//                finish();
//                if (runnable!=null){
//                    handler.removeCallbacks(runnable);
//                }
//                break;

        //       }



    }
}
